<?php

$cat1 = $blog->GetCatList($blogid, 'ee_blog_categories1');
$title = "添加一级分类";
$url = "index.php?Action=Class1";
if($_GET['CatId'])
{
	$info = $blog->getInfo($_GET['CatId'], 'ee_blog_categories1');
	if(!$info)
	{
		echo "该分类不存在";
		exit();
	}
	$title = "编辑一级分类";
	$url = "index.php?Action=Class1&CatId={$_GET['CatId']}";
}
if($_SERVER['REQUEST_METHOD']=='POST')
{
	$data = array();
	$data['F_ID_BLOG_INFO'] = $blogid;
	$data['F_CATEGORIES_NAME'] = $_POST['cat_name'];
	if($_GET['CatId'])
	{
		$blog->updateData('ee_blog_categories1',$_GET['CatId'],$data);
		echo "<script type=\"text/javascript\">";
	    echo "window.location='index.php?Action=Class1';";
	    echo "</script>";
		exit();
	}else {
		$blog->insertData('ee_blog_categories1',$data);
		echo "<script type=\"text/javascript\">";
	    echo "window.location='index.php?Action=Class1';";
	    echo "</script>";
		exit();
	}
}

?>
<div class="tab-content show" id="chapter-manage">
<a class="current" href="index.php?Action=Class1">一级分类</a>
<a href="index.php?Action=Class">二级分类</a>
</div>
</div>
<div id="content">
<div class="admin-form">
<h3>一级分类列表</h3>
<?php
if(!$_GET['CatId'])										//判断是否为编辑状态,不是则显示分类列表
{
?>
<table>
<thead>
	<tr>
    <th>分类ID</th>
    <th>分类名称</th>
    <th colspan="2">操作</th>
    </tr>
</thead>
<tbody>
<?php
foreach($cat1 as $value)
{
?>
  <tr>
	<td><?php echo $value['F_ID'] ?></td>
	<td><?php echo $value['F_CATEGORIES_NAME'] ?></td>
	<td><a href="index.php?CatId=<?php echo $value['F_ID'] ?>&Action=Class1">编辑</a></td>
	<td>
	<a href="index.php?CatId=<?php echo $value['F_ID'] ?>&Action=Class1Del" onclick="javascript:confirm('真的要删除吗?')">删除</a>
	</td>
  </tr>
<?php
}
?>
</tbody>
</table>
<?php
}
?>

<form action="<?php echo $url?>" method="post">
<fieldset>
	<legend><?php echo $title ?>表单</legend>
	<dl>
	  <dt>分类名称：</dt><dd><input id="cat_name" size=40 name="cat_name" value="<?php echo $info['F_CATEGORIES_NAME']?>"></dd>
	</dl>
	<dl>
	  <dd class="submit-button"><input type=submit value="<?php echo $title?>" name=submit></dd>
	</dl>
</fieldset>
</form></div></div>